package com.chuangjiangx.member.stored.ddd.domain.subscribe;

import com.chuangjiangx.commons.JacksonUtils;
import com.chuangjiangx.member.stored.ddd.dal.mapper.MbrOrderPayDalMapper;
import com.chuangjiangx.member.stored.ddd.domain.event.MbrRefundSuccessEvent;
import com.chuangjiangx.member.stored.ddd.domain.model.TradeCallBackMbr;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;

/**
 * @author cj-ch
 * @date 2018/5/23 下午3:54
 * 监听移动支付的退款成功事件
 */
@Slf4j
public class MbrOldOrderRefundSuccessListener extends MbrRefundSuccessListener{


    @Autowired
    protected MbrOrderPayDalMapper mbrOrderPayDalMapper;

    /**
     * 负责吧移动支付的退款信息转换为 MbrRefundSuccessEvent
     * @param message
     * @return
     */
    @Override
    protected MbrRefundSuccessEvent convertMessage(Serializable message) {
        log.info("***接收到移动支付退款成功的信息:{}***",message);
        /**
         * 组装 MbrRefundSuccessEvent 需要的参数即可
         */
        TradeCallBackMbr callBackMbr = JacksonUtils.toObject(objectMapper, message.toString(), TradeCallBackMbr.class);

        MbrRefundSuccessEvent.MbrRefundSuccessEventBuild build = new MbrRefundSuccessEvent.MbrRefundSuccessEventBuild();
        MbrRefundSuccessEvent event = build
                .setPayTerminal(callBackMbr.getPayTerminal())
                .setPayType(callBackMbr.getPayType())
                .setPayEntry(callBackMbr.getPayEntry())
                .setPayChannelId(callBackMbr.getPayChannel())
                .setOrderPayNumber(callBackMbr.getOrderNumber())
                .setAmount(callBackMbr.getAmount())
                .setRealPayAmount(callBackMbr.getRealPayAmount())
                .setMerchantId(callBackMbr.getMerchantId())
                .setMerchantUserId(callBackMbr.getMerchantUserId())
                .setCurrentRefundAmout(callBackMbr.getRefundAmount())
                .setTotalRefundAmout(callBackMbr.getRefundedAmount())
                .setOrderRefundNumber(callBackMbr.getRefundNumber())
                .setMemberId(callBackMbr.getMemberId())
                .build();

        return event;
    }
}
